/**
 * Copyright 2011 HNB. All rights reserved.
 * HNB PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package my.hnb.android.adapter;

import java.util.ArrayList;

import my.hnb.android.dto.SongDTO;
import my.hnb.android.listenner.OnEventListener;
import my.hnb.android.view.karaoke.KaraokeSongRow;
import my.hnb.android.view.karaoke.ListSongsView;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

/**
 * Adapter bai hat karaoke
 * @author BANGHN
 */
public class SongAdapter extends BaseAdapter {
	OnEventListener listener;
	private Context context;
	private ArrayList<SongDTO> listSong;
	ListSongsView songView;
	OnEventListener listenner;
	public SongAdapter(Context ct, ArrayList<SongDTO> listDTO){
		listSong = listDTO;
		context = ct;
		songView = (ListSongsView) ct;
		listenner = (OnEventListener) ct;
		this.listener = (OnEventListener) ct;
	}
	
	public void updateListSongs(ArrayList<SongDTO> listDTO){
		listSong = listDTO;
	}
	
	@Override
	public int getCount() {
		if(listSong != null)
			return listSong.size();
		
		return 0;
	}

	@Override
	public Object getItem(int position) {
		return listSong.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if(convertView == null){
			convertView = new KaraokeSongRow(context);
		}
		//convertView.setTag(getItem(position));
		((KaraokeSongRow)convertView).renderInfoSong((SongDTO) getItem(position), position);
		
		if(position == (listSong.size() - 40)){
			//listener.onEvent(0, ListSongsView.ACTION_LOAD_MORE, null);s
			songView.loadingControl.handleLoading();
		}
		return convertView;
	}

}
